package com.yhsoft.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yhsoft.sys.entity.NoticeUsers;
import com.yhsoft.sys.entity.User;
import com.yhsoft.sys.mapper.NoticeUsersMapper;
import com.yhsoft.sys.service.INoticeUsersService;
import com.yhsoft.sys.service.IUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 公告和用户关联表 服务实现类
 * </p>
 *
 * @author yyyyyyyh
 * @since 2023-11-27
 */
@Service
public class NoticeUsersServiceImpl extends ServiceImpl<NoticeUsersMapper, NoticeUsers> implements INoticeUsersService {

    @Resource
    private IUserService iUserService;

    @Override
    public void add(Integer noticeId, String type, String range) {
        // type类型 1-全部、2-仅平台、3-全部渠道商、4-全部供应商、5-供应商列表、6-渠道商列表
        LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();

        if(type.equals("1")){

        } else if (type.equals("2")) {
            wrapper.eq(User::getSysType, "sys");
        } else if (type.equals("3")) {
            wrapper.eq(User::getSysType, "saler");
        } else if (type.equals("4")) {
            wrapper.eq(User::getSysType, "vender");
        } else if (type.equals("5")) {
            wrapper.eq(User::getSysType, "vender");
            wrapper.in(User::getCompanyId, range);
        } else if (type.equals("6")) {
            wrapper.eq(User::getSysType, "saler");
            wrapper.in(User::getCompanyId, range);
        }
        List<User> list = iUserService.list(wrapper);
        list.forEach(user ->{
            NoticeUsers users = new NoticeUsers();
            users.setNoticeId(noticeId);
            users.setUserId(user.getId());
            users.setReadStatus(0);
            users.setDeleted(0);
            this.getBaseMapper().insert(users);
        });
    }
}
